package com.commods.main.view.components.historicalChart.renderers.axis
{
	import com.commods.main.view.components.historicalChart.proto.temp.TempUtils;
	import com.commods.main.view.components.historicalChart.proto.temp.VDashRule;
	
	import flash.geom.Point;
	
	import mx.charts.AxisRenderer;
	import mx.charts.DateTimeAxis;
	import mx.charts.LineChart;
	import mx.charts.series.LineSeries;
	import mx.collections.ArrayCollection;
	import mx.messaging.SubscriptionInfo;
	import mx.utils.StringUtil;
	
	public class RTimeAxisRenderer extends AxisRenderer
	{
		public function RTimeAxisRenderer()
		{
			super();
		}
		
		private static const NUM:Number = 3;
		private var _lines:ArrayCollection = new ArrayCollection();
		override protected function createChildren():void{
			super.createChildren();
			for(var i:uint=0; i<NUM; i++){
				var curLine:VDashRule =  new VDashRule();
			//	curLine.visible = false;
				_lines.addItem(curLine);
				addChild(curLine);
			}
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
			var daxis:DateTimeAxis = (this.chart as LineChart).horizontalAxis as DateTimeAxis;
			var diff:Number = (daxis.maximum.time-daxis.minimum.time)/(NUM+1);

			if(diff<1000)return;
			var curDate:Date = daxis.minimum;
			var targetSeri:LineSeries = ((this.chart as LineChart).series[0] as LineSeries);
			for(var i:uint=0; i<_lines.length; i++){
				curDate =  new Date(curDate.time+diff);
				var curLine:VDashRule = _lines.getItemAt(i) as VDashRule;
				curLine.bottomLabelText = StringUtil.substitute("-{0}s", Math.floor((daxis.maximum.time - curDate.time)/1000));
				
				var pt:Point = targetSeri.dataToLocal(curDate);
				curLine.height = unscaledHeight;
				curLine.move(pt.x, pt.y);
				
			}
	
		}
	}
}